package com.mcxx.util;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.mcxx.modules.miniSalvation.family.dto.FamilyDTO;
import com.mcxx.result.BaseResult;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.*;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

import java.util.*;


@Component
public class ScheduleRequestUtil {
    @Value("society.http.schedule-url")
    private String scheduleUrl;

    @Value("society.http.appKey")
    private String appKey;

    @Value("society.http.appSecurity")
    private String appSecurity;


    public ResponseEntity<BaseResult> postSyncRequest(String uri, String currUser, Object requestBody, Map<String, Object> params) {
        HttpHeaders httpHeaders = new HttpHeaders();
        httpHeaders.set("username", currUser);
        httpHeaders.set("appKey", appKey);
        httpHeaders.set("appSecurity", appSecurity);
        RestTemplate restTemplate = new RestTemplate();

        String url = scheduleUrl + uri;
        HttpEntity httpEntity = new HttpEntity<>(params, httpHeaders);
        ResponseEntity responseEntity = restTemplate.exchange(url, HttpMethod.POST, httpEntity, String.class);
        return responseEntity;
    }


    public ResponseEntity<BaseResult> postSyncRequest(String uri, String currUser, Object requestBody) {
        return postSyncRequest(uri, currUser, requestBody, new HashMap<>());
    }



    public static void main(String[] args) {
//        String scheduleUrl = "http://10.72.6.52:8089/mint/checkService/status/update";

//        httpHeaders.add("Accept", MediaType.ALL_VALUE);















//        params.put("bizContent",JSONObject.toJSONString(list));


//        ResponseEntity responseEntity = restTemplate.exchange(scheduleUrl, HttpMethod.POST, httpEntity, String.class);
//        System.out.println(responseEntity);
        ScheduleRequestUtil scheduleRequestUtil = new ScheduleRequestUtil();



        Gson gson= new GsonBuilder().serializeNulls().create();
        FamilyDTO familyDTO = new FamilyDTO();
        familyDTO.setApplyName("123");
        System.out.println(gson.toJson(familyDTO));
    }
    public void testPushStates(){
        String scheduleUrl = "http://10.72.6.52:8089/mint/checkService/status/query";
        HttpHeaders httpHeaders = new HttpHeaders();
        httpHeaders.add("Accept", MediaType.ALL_VALUE);
        httpHeaders.set("username", "developer");
        httpHeaders.set("appKey", "society-save");
        httpHeaders.set("appSecurity", "0x62BA52D13F4F4FB0B0F7217AAD6C9048");
        Map<String, Object> params = new HashMap<>();
        JSONObject json = new JSONObject();
        json.put("businessCode","110");
        List<String> ids=Arrays.asList("57A89215D6004D429D3550E3CA9D6879");
        json.put("checkids",ids);
        params.put("bizcontent",json.toString());
        RestTemplate restTemplate = new RestTemplate();
        HttpEntity httpEntity = new HttpEntity<>(params, httpHeaders);
        ResponseEntity responseEntity = restTemplate.exchange(scheduleUrl, HttpMethod.POST, httpEntity, String.class);
        System.out.println(responseEntity);
    }

    public void testUpdateCheck(){
        String scheduleUrl = "http://10.72.6.52:8089/mint/checkService/status/update";
        HttpHeaders httpHeaders = new HttpHeaders();
        httpHeaders.add("Accept", MediaType.ALL_VALUE);
        httpHeaders.set("username", "developer");
        httpHeaders.set("appKey", "society-save");
        httpHeaders.set("appSecurity", "0x62BA52D13F4F4FB0B0F7217AAD6C9048");
        Map<String, Object> params = new HashMap<>();
        JSONArray array = new JSONArray();
        JSONObject json = new JSONObject();

        json.put("BBEX0001","4303211070002021080900374616370");

        json.put("BBEE0001","3aea8c3fd0594ab5be5e63adfacd691e");

        json.put("BBEE0002","7f31ddd8b0d14db29b5ffffb05ca3370");

        json.put("BBEX0012","2021-08-10");

        json.put("BBEX0003","05");

        json.put("BBEX0004","这里是备注");

        json.put("BBEX0005","这里是异常");
        array.add(json);
        params.put("bizcontent",array.toString());
        RestTemplate restTemplate = new RestTemplate();
        HttpEntity httpEntity = new HttpEntity<>(params, httpHeaders);
        ResponseEntity responseEntity = restTemplate.exchange(scheduleUrl, HttpMethod.POST, httpEntity, String.class);
        System.out.println(responseEntity);
    }


    public void testAuditResult(){
        String scheduleUrl = "http://10.72.6.52:8089/mint/checkService/audit/result";
        HttpHeaders httpHeaders = new HttpHeaders();
        httpHeaders.add("Accept", MediaType.ALL_VALUE);
        httpHeaders.set("username", "developer");
        httpHeaders.set("appKey", "society-save");
        httpHeaders.set("appSecurity", "0x62BA52D13F4F4FB0B0F7217AAD6C9048");
        Map<String, Object> params = new HashMap<>();
        JSONObject body = new JSONObject();
        JSONObject json = new JSONObject();

        json.put("businessCode","110");

        List<String> ids = Arrays.asList("c4bd9c6c3706492592fd618410de4362");
        json.put("orderids",ids);
        params.put("bizcontent",json.toString());
        RestTemplate restTemplate = new RestTemplate();
        HttpEntity httpEntity = new HttpEntity<>(params, httpHeaders);
        ResponseEntity responseEntity = restTemplate.exchange(scheduleUrl, HttpMethod.POST, httpEntity, String.class);
        System.out.println(responseEntity);
    }


    public void testCheckQuery(){
        String scheduleUrl = "http://10.72.6.52:8089/mint/checkService/status/query";
        HttpHeaders httpHeaders = new HttpHeaders();
        httpHeaders.add("Accept", MediaType.ALL_VALUE);
        httpHeaders.set("username", "developer");
        httpHeaders.set("appKey", "society-save");
        httpHeaders.set("appSecurity", "0x62BA52D13F4F4FB0B0F7217AAD6C9048");
        Map<String, Object> params = new HashMap<>();
        JSONObject body = new JSONObject();
        JSONObject json = new JSONObject();
        json.put("businessCode","110");

        List<String> ids = Arrays.asList("FC6E4E19ACB04E769C979BB7EF155D69");
        json.put("checkids",ids);
        params.put("bizcontent",json.toString());
        RestTemplate restTemplate = new RestTemplate();
        HttpEntity httpEntity = new HttpEntity<>(params, httpHeaders);
        ResponseEntity responseEntity = restTemplate.exchange(scheduleUrl, HttpMethod.POST, httpEntity, String.class);
        System.out.println(responseEntity);
    }
}
